package Test06;

//转换流

import java.io.*;
import java.nio.charset.Charset;

/*
    将本地文件中的GBK文件，转成UTF-8
 */
public class Test27 {
    public static void main(String[] args) throws IOException {

        /*//JDK11以前的方案
        //1、创建对象
        InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\工作\\src\\a.txt"), "GBK");
        OutputStreamWriter osr = new OutputStreamWriter(new FileOutputStream("D:\\工作\\src\\b.txt"), "UTF-8");

        //2、读取数据，写出数据
        int ch;
        while ((ch = isr.read()) != -1){
            osr.write(ch);
        }

        //3、释放资源
        osr.close();
        isr.close();*/

        System.out.println("----------------------------------------------------------------------------------------------");

        //JDK11以后的方案
        //1、创建对象
        FileReader fr = new FileReader("D:\\工作\\src\\a.txt", Charset.forName("GBK"));
        FileWriter fw = new FileWriter("D:\\工作\\src\\b.txt", Charset.forName("UTF-8"));

        //2、读取数据，写出数据
        int ch;
        while ((ch = fr.read()) != -1){
            fw.write(ch);
        }

        //3、释放资源
        fw.close();
        fr.close();
    }
}
